﻿#region Using directives
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using AlphaMobileControls;
using System.Drawing;
#endregion

namespace gpsMe.UI.Components
{
    public class gpsMeAlphaProgressBar : AlphaPanel
    {
        #region Constants
        private const int DEFAULT_MIN_VALUE = 0;
        private const int DEFAULT_MAX_VALUE = 100;
        #endregion

        #region Controls
        private AlphaPictureBox backgroundImage;
        private AlphaPictureBox foregroundImage;
        #endregion

        #region Accessors
        /// <summary>
        /// Current value of the progress bar
        /// </summary>
        public int Value
        {
            get
            {
                return this._Value;
            }

            set
            {
                if ((value >= this.MinValue) && (value <= this.MaxValue))
                {
                    this._Value = value;
                    //this.foregroundImage.Width = (this.Width / (this.MaxValue - this.MinValue)) * (this.Value / (this.MaxValue - this.MinValue));
                    this.Invalidate();
                }
                else
                {
                    throw new InvalidOperationException("Value must be placed between MinValue and MaxValue");
                }
            }
        }
        private int _Value;

        /// <summary>
        /// Min value of the progress bar
        /// </summary>
        public int MinValue { get; set; }

        /// <summary>
        /// Max value of the progress bar
        /// </summary>
        public int MaxValue { get; set; }
        #endregion

        #region Constructor
        /// <summary>
        /// Constructor of the progress bar
        /// </summary>
        /// <param name="p_sBackgroundImagePath">Path to the background image of the progress bar</param>
        /// <param name="p_sForegroundImagePath">Path to the foreground image of the progress bar</param>
        public gpsMeAlphaProgressBar(string p_sBackgroundImagePath, string p_sForegroundImagePath)
        {
            this.SuspendLayout();
            /* PictureBoxes initialization */
            this.foregroundImage = new AlphaPictureBox();
            this.backgroundImage = new AlphaPictureBox();
            this.foregroundImage.Image = AlphaImage.CreateFromFile(p_sForegroundImagePath);
            this.backgroundImage.Image = AlphaImage.CreateFromFile(p_sBackgroundImagePath);
            this.foregroundImage.Location = new Point(0, 0);
            this.backgroundImage.Location = new Point(0, 0);

            /* Controls attachment */
            this.Controls.Add(this.foregroundImage);
            this.Controls.Add(this.backgroundImage);
            this.ResumeLayout();

            /* Values default initialization */
            this.MinValue = DEFAULT_MIN_VALUE;
            this.MaxValue = DEFAULT_MAX_VALUE;
            this.Value = DEFAULT_MIN_VALUE;

            /* Form Listeners Initialization */
            this.Resize += new EventHandler(gpsMeAlphaProgressBar_Resize);
            this.BackColor = Color.Transparent;
        }
        #endregion

        #region Methods / Functions / Events
        /// <summary>
        /// Method invoked when progress bar is resized
        /// </summary>
        /// <param name="p_oSender"></param>
        /// <param name="p_oEventArgs"></param>
        private void gpsMeAlphaProgressBar_Resize(object p_oSender, EventArgs p_oEventArgs)
        {
            this.backgroundImage.Size = this.Size;
            this.foregroundImage.Height = this.Height;
            this.foregroundImage.Width = 100; //(this.Width / (this.MaxValue - this.MinValue)) * (this.Value / (this.MaxValue - this.MinValue));
        }
        #endregion
    }
}
